import numpy as np


bite_split = 1    #0代表：上下切割； 1代表：左右切割

def blodprocess(image):
    # print(image)
    try:
        x0 = np.sum(image * np.arange(1, image.shape[1] + 1), dtype=np.int64) / np.sum(image)
        y0 = np.sum(image.T * np.arange(1, image.shape[0] + 1), dtype=np.int64) / np.sum(image)
        # print(np.sum(np.arange(1, image.shape[1] + 1)*image), np.sum(image.T * np.arange(1, image.shape[0] + 1)), np.sum(image))

        if bite_split == 0:
            upper, lower = np.split(image, [int(y0)], axis=0)
            # print(upper.shape)

            x1 = np.sum(upper * np.arange(1, upper.shape[1] + 1), dtype=np.int64) / np.sum(upper)
            y1 = np.sum(upper.T * np.arange(1, upper.shape[0] + 1), dtype=np.int64) / np.sum(upper)

            x2 = np.sum(lower * np.arange(1, lower.shape[1] + 1), dtype=np.int64) / np.sum(lower)
            y2 = np.sum(lower.T * np.arange(1, lower.shape[0] + 1), dtype=np.int64) / np.sum(lower)

        elif bite_split == 1:
            left, right = np.split(image, [int(x0)], axis=1)

            x1 = np.sum(left * np.arange(1, left.shape[1] + 1), dtype=np.int64) / np.sum(left)
            y1 = np.sum(left.T * np.arange(1, left.shape[0] + 1), dtype=np.int64) / np.sum(left)

            x2 = np.sum(right * np.arange(1, right.shape[1] + 1), dtype=np.int64) / np.sum(right)
            y2 = np.sum(right.T * np.arange(1, right.shape[0] + 1), dtype=np.int64) / np.sum(right)
        return (x0,y0,x1,y1,x2,y2)

    except Exception as e:
        raise e('无法进行图像处理')

